from threading import Thread
import threading
import time,random


class TheadingLocalTest(Thread):

    def __init__(self, index, create_time):
        Thread.__init__(self)
        self.index = index
        self.create_time = create_time
        self.local = threading.local()

    def run(self) -> None:
        time.sleep(random.random())
        print("线程开始")
        print(self.create_time, self.index)
        print("线程%d退出", self.index)
        self.local.num = []
        for i in range(10):
            self.local.num.append(random.choice(range(10)))
            print(threading.current_thread(), self.local.num)
        print(threading.current_thread(), self.local.num)



if __name__ == '__main__':
    threads = []
    for i in range(5):
        test = TheadingLocalTest(i, time.time())
        test.start()
        threads.append(test)

    for thread in threads:
        thread.join()

    print("我是主线程")


